function login() {

    var redirectUrl = getQueryString('redirectUrl');
    var clientId = getQueryString('clientId');

    var url = 'login';
    if (redirectUrl.length != 0) {
        url = url + '?redirectUrl=' + redirectUrl + '&clientId=' + clientId;
    }

    $.ajax({
        type: 'post',
        url: url,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(
            {
                username: $("#username").val(),
                password: $("#password").val()
            }
        ),
        success: function (data) {
            console.log(data);
            var responseData = data['data'];
            console.log(responseData);
            if (responseData['isLogin'] == true) {
                console.log("登录成功，准备重定向");
                if (responseData['redirectUrl'].indexOf('?') != -1) {
                    var redirectUrl = responseData['redirectUrl'] + '&ssoTicket=' + responseData['ssoTicket'];
                } else {
                    var redirectUrl = responseData['redirectUrl'] + '?ssoTicket=' + responseData['ssoTicket'];
                }
                alert(redirectUrl);
                window.location.href = redirectUrl;
            } else {
                alert("登录失败，请重试");
            }
        },
        error: function (data) {
            console.log("请求失败！！！");
        }
    });

}


function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    } else {
        return null;
    }
}


